﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IndirectX.Windows
{
    public class RenderForm : Form
    {
        
        public RenderForm(string title)
        {
            this.Text = title;
            this.ResizeBegin += RenderForm_ResizeBegin;
        }

        void RenderForm_ResizeBegin(object sender, EventArgs e)
        {
            if (UserResized != null)
            {
                UserResized(this, e);
            }
        }


        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);


            this.SetStyle(ControlStyles.AllPaintingInWmPaint |  ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
            this.DoubleBuffered = true;

            if (UserResized != null)
            {
                UserResized(this, e);
            }
        }


        public event Action<object, object> UserResized;

        public Bitmap Surface;

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (Surface != null)
            {
                e.Graphics.DrawImage(Surface, 0, 0);
            }
           
        
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // RenderForm
            // 
            this.ClientSize = new System.Drawing.Size(304, 202);
            this.DoubleBuffered = true;
            this.Name = "RenderForm";
            this.ResumeLayout(false);

        }
    }
}
